<?php

class AvaliacaoController extends Controller {

    /**
     * @final   pacote das views deste controller
     */
    const PACKAGE_VIEW = 'avaliacao';
    /**
     * @var AtendimentoService
     */
    private $atendimentoService;
    /**
     * @var AvaliacaoService
     */
    private $avaliacaoService;
    /**
     * @var UsuarioService
     */
    private $usuarioService;
    /**
     * @var SetorService
     */
    private $setorService;
    /**
     * @var DepartamentoService
     */
    private $departamentoService;

    public function __construct() {
        $this->atendimentoService = AtendimentoService::getInstance();
        $this->avaliacaoService = AvaliacaoService::getInstance();
        $this->usuarioService = UsuarioService::getInstance();
        $this->setorService = SetorService::getInstance();
        $this->departamentoService = DepartamentoService::getInstance();
    }

    public function listarAvaliacoes() {
        $this->save(SESSION_INTERFACE, 'Report', $this->atendimentoService->generateIndividualReport());
        $this->view('listar_avaliacoes', self::PACKAGE_VIEW);
    }

    public function filter() {
        $filterType = treatUrl('type');
        $IDFilter = $_POST['filterkey'];
        multipleEntities($IDFilter);
        $this->save(SESSION_INTERFACE, 'Report', $this->avaliacaoService->findByFilter($IDFilter, $filterType));

        if( $IDFilter == 'list-evaluation-user' ) {
            $this->view('userevaluationtablelist', self::PACKAGE_VIEW, true);
        } else if( $IDFilter == 'list-evaluation-sector' ) {
            $this->view('sectorevaluatuationtablelist', self::PACKAGE_VIEW, true);
        } else if( $IDFilter == 'list-evaluation-departament' ) {
            $this->view('departamentevaluatuationtablelist', self::PACKAGE_VIEW, true);
        }
    }

    public function visualizarAvaliacao() {
        if( treatUrl('usuario') ) {
            $this->visualizarAvaliacaoUsuario();
        } else if( treatUrl('setor') ) {
            $this->visualizarAvaliacaoSetor();
        } else if( treatUrl('departamento') ) {
            $this->visualizarAvaliacaoDepartamento();
        }
    }

    private function visualizarAvaliacaoUsuario() {
        $IDUsuario = treatUrl('usuario');
        multipleEntities($IDUsuario);
        $Usuario = $this->usuarioService->findById($IDUsuario);
        $this->save(SESSION_INTERFACE, 'AvaliacoesList', $this->avaliacaoService->findByUser($IDUsuario) );
        $this->save(SESSION_INTERFACE, 'UsuarioView', $Usuario );
        $this->save(SESSION_INTERFACE, 'AvaliacaoUsuario', $this->avaliacaoService->countEvaluationByUser($IDUsuario) );
        $this->view('visualizar_avaliacao_usuario', self::PACKAGE_VIEW);
    }

    public function visualizarAvaliacaoSetor() {
        $IDSetor = treatUrl('setor');
        multipleEntities($IDSetor);
        $Setor = $this->setorService->findSimpleById($IDSetor);
        $this->save(SESSION_INTERFACE, 'AvaliacoesList', $this->avaliacaoService->findBySector($IDSetor) );
        $this->save(SESSION_INTERFACE, 'SetorView', $Setor );
        $this->save(SESSION_INTERFACE, 'AvaliacaoSetor', $this->avaliacaoService->countEvaluationBySector($IDSetor) );
        $this->view('visualizar_avaliacao_setor', self::PACKAGE_VIEW);
    }

    public function visualizarAvaliacaoDepartamento() {
        $IDDepartamento = treatUrl('departamento');
        multipleEntities($IDDepartamento);
        $Departamento = $this->departamentoService->findSimpleById($IDDepartamento);
        $this->save(SESSION_INTERFACE, 'AvaliacoesList', $this->avaliacaoService->findByDepartament($IDDepartamento) );
        $this->save(SESSION_INTERFACE, 'DepartamentoView', $Departamento );
        $this->save(SESSION_INTERFACE, 'AvaliacaoDepartamento', $this->avaliacaoService->countEvaluationByDepartament($IDDepartamento) );
        $this->view('visualizar_avaliacao_departamento', self::PACKAGE_VIEW);
    }

}

?>
